package com.huichaoliu.adapters;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.huichaoliu.app.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class OrderAdapter extends BaseAdapter {

	private Context mContext = null;
	private JSONArray ja = null;
	public OrderAdapter(Context mContext,JSONArray ja){
		this.mContext = mContext;
		this.ja = ja;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return ja.length();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if(convertView == null){
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_order, null);
			holder = new ViewHolder();
			holder.init(convertView);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder)convertView.getTag();
		}
//		try{
//			JSONObject jo = ja.getJSONObject(position);
//			holder.tv_title.setText(jo.getString(""));
//		}catch(JSONException e){
//			e.printStackTrace();
//		}
		return convertView;
	}
	
	static class ViewHolder{
		private ImageView ic_cover;
		private TextView tv_title;
		private TextView tv_price;
		private TextView tv_order_info;
		private TextView tv_operate;
		
		private void init(View view){
			tv_operate = (TextView)view.findViewById(R.id.tv_operate);
			ic_cover = (ImageView)view.findViewById(R.id.ic_cover);
			tv_title = (TextView)view.findViewById(R.id.tv_title);
			tv_price = (TextView)view.findViewById(R.id.tv_price);
			tv_order_info = (TextView)view.findViewById(R.id.tv_order_info);
		}
	}
}
